<template>
  <div class="content">
    <ul class="firstctgy">
      <li
        :class="{
          'firstctgy-item': true,
          'firstctgy-item_active': firstCtgyActiveIndex === index,
        }"
        v-for="(firstctgy, index) in firstCtgyList"
        :key="firstctgy.firstctgyId"
        @click="changeTab(index)"
      >
        <span class="firstctgyname">{{ firstctgy.firstctgyname }}</span>
      </li>
    </ul>
    <div class="secondthrdctgy">
      <ul>
        <li
          class="secondthrdctgy-item"
          v-for="(item, index) in secondCtgyList"
          :key="item.secondctgyid"
        >
          <div class="secondctgy-item">
            <span class="secctgyname">{{ item.secctgyname }}</span>
            <span class="secctgynameshop"
              >{{ item.secctgyname }}馆
              <i class="iconfont icon-xiangyoujiantou"></i>
            </span>
          </div>
          <ThrdCtgy
            :isReadOpen="item.isReadyOpen"
            :secondctgy="item"
            :thrdCtgys="item.thirdctgys"
            :subthrdctgys="item.subThirdCtgys"
          ></ThrdCtgy>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import FirstToThirdCtgy from "../service"
import ThrdCtgy from "./ThrdCtgy.vue"
const {
  storeRefs: { firstCtgyList, secondCtgyList },
} = FirstToThirdCtgy
const { getFirstCtgys, changeTab, getSecThrdCtgyList, firstCtgyActiveIndex } =
  FirstToThirdCtgy

getFirstCtgys() // 获取1级分类并保存到 pinia 的 state 中
getSecThrdCtgyList() // 获取2级分类(包含3级分类)并保存到 pinia 的 state 中
</script>

<style lang="scss" scoped>
.content {
  display: flex;
  column-gap: 0.1rem;
  position: absolute;
  top: 1.02rem;
  bottom: 0.855rem;
  left: 0;
  right: 0;
  font-size: .2rem;

  .firstctgy {
    flex-basis: 1.3rem;
    overflow-y: auto;

    &-item {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 0.78rem;
    }

    &-item_active {
      color: red;
      text-shadow: 0 0 0.3rem #2a2a2a;
      background-color: #f7f7f7;

      .firstctgyname {
        border-left: 3px solid red;
        width: 100%;
        text-align: center;
      }
    }
  }

  .secondthrdctgy {
    overflow-y: auto;
    flex-grow: 1;
    /* 分配剩余空间 */
    margin-right: 0.19rem;

    &-item {
      .secondctgy-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 0.735rem;
        font-size: 0.2rem;

        .secctgyname {
          color: #0d0d0d;
          font-weight: bold;
        }

        .secctgynameshop {
          color: #535353;
        }
      }
    }
  }
}
</style>
